Calculate the harmonic sum of N - 1¶
Calculate the harmonic sum of N - 1.
Note:
The harmonic sum is the sum of reciprocals of the positive integers.
The reciprocal is the quantity obtained by dividing the number
one by a given quantity.
Example:
harmonic series
def harmonic_sum(N):
if N < 2:
return 1
else:
return 1 / N + (harmonic_sum(N - 1))
# test
print(harmonic_sum(7)) # 2.5928571428571425
print(harmonic_sum(4)) # 2.083333333333333